674a78b30d64fbbb34846dd047494888870e176a,src/Grepolis/GrepolisBot.java,BuildDocksTroops,run,#,458

Before Change


                if (town.getBuilding(Building.BuildingType.docks).getCurrentLevel() > 0) {

                    final boolean[] hasDocksData = {false};
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            webView.getEngine().executeScript("function readBody(xhr) {\n" +
                                    "    var data;\n" +
                                    "    if (!xhr.responseType || xhr.responseType === \"text\") {\n" +
                                    "        data = xhr.responseText;\n" +
                                    "    } else if (xhr.responseType === \"document\") {\n" +
                                    "        data = xhr.responseXML;\n" +
                                    "    } else {\n" +
                                    "        data = xhr.response;\n" +
                                    "    }\n" +
                                    "    return data;\n" +
                                    "}\n" +
                                    "\n" +
                                    "var xhr = new XMLHttpRequest();\n" +
                                    "var docksData;\n" +
                                    "xhr.onreadystatechange = function() {\n" +
                                    "    if (xhr.readyState == 4) {\n" +
                                    "        docksData = readBody(xhr);\n" +
                                    "        alert(\"DocksData:\" +xhr.status +readBody(xhr));\n" +
                                    "    }\n" +
                                    "}\n" +
                                    "xhr.open('GET', 'https://" + server + ".grepolis.com/game/building_docks?town_id=" + town.getId() + "&action=index&h=" + csrfToken + "&json=%7B%22town_id%22%3A" + town.getId() + "%2C%22nl_init%22%3Atrue%7D', true);\n" +
                                    "xhr.send(null);");
                        }
                    });
                } else {
                    builtDocksTroops = true;
                }

After Change


                do {
                    Thread.sleep(randInt(250, 500));
                } while (!builtBarracksTroops);
                boolean forceUpdate = randInt(0, 2) == 1 || town.getDocks().canBuildUnit();

                if (town.getBuilding(Building.BuildingType.docks).getCurrentLevel() > 0 && forceUpdate) {
                    Thread.sleep(randInt(1250, 2500));
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            webView.getEngine().executeScript("function readBody(xhr) {\n" +
                                    "    var data;\n" +
                                    "    if (!xhr.responseType || xhr.responseType === \"text\") {\n" +
                                    "        data = xhr.responseText;\n" +
                                    "    } else if (xhr.responseType === \"document\") {\n" +
                                    "        data = xhr.responseXML;\n" +
                                    "    } else {\n" +
                                    "        data = xhr.response;\n" +
                                    "    }\n" +
                                    "    return data;\n" +
                                    "}\n" +
                                    "\n" +
                                    "var xhr = new XMLHttpRequest();\n" +
                                    "var docksData;\n" +
                                    "xhr.onreadystatechange = function() {\n" +
                                    "    if (xhr.readyState == 4) {\n" +
                                    "        docksData = readBody(xhr);\n" +
                                    "        alert(\"DocksData:\" +xhr.status +readBody(xhr));\n" +
                                    "    }\n" +
                                    "}\n" +
                                    "xhr.open('GET', 'https://" + server + ".grepolis.com/game/building_docks?town_id=" + town.getId() + "&action=index&h=" + csrfToken + "&json=%7B%22town_id%22%3A" + town.getId() + "%2C%22nl_init%22%3Atrue%7D', true);\n" +
                                    "xhr.send(null);");
                        }
                    });
                } else {
                    builtDocksTroops = true;
                }